package cn.tedu.property_management_system.service.Impl;


import cn.tedu.property_management_system.entity.Building;
import cn.tedu.property_management_system.mapper.BuildingMapper;
import cn.tedu.property_management_system.service.IBuildingService;
import cn.tedu.property_management_system.utils.JsonPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class IBuildingServiceImpl implements IBuildingService {
    @Autowired
    BuildingMapper mapper;


    public List<Building> select(Building building) {
        return mapper.select(building);
    }


    public void insert(Building building) {
        building.setTime1(System.currentTimeMillis());
        mapper.insert(building);
    }


    public List<Building> list() {
        return mapper.selectList();
    }


    public Building editSelect( Building building) {
        return mapper.editSelect(building.getId());
    }


    public void update(Building building) {
        building.setTime1(System.currentTimeMillis());
        mapper.update(building);

    }


    public void delete(Building building) {
        mapper.delete(building.getId());
    }


    public int deletes(List<Building> list) {
        if (list.size() > 0) {
            for (Building building : list) {
                mapper.delete(building.getId());
            }
            return 1;
        } else {
            return 2;
        }
    }


    public List<String> floor() {
        System.out.println(mapper.floor());
        return mapper.floor();
    }




    public JsonPage<Building> pageSelect(Integer pageSize, Integer pageIndex){
        PageHelper.startPage(pageSize,pageIndex);
        List<Building> list=mapper.selectList();
        return JsonPage.restPage(new PageInfo<>(list));
    }


}
